//
//  AVDataInfoTableViewDelegateSource.m
//  Rongcloud
//
//  Created by LiuLinhong on 2018/02/06.
//  Copyright © 2018年 Beijing Rongcloud Network Technology Co. , Ltd. All rights reserved.
//

#import "AVDataInfoTableViewDelegateSource.h"
#import "MeetingViewController.h"
#import "MeetingLocalDataInfoModel.h"
#import "MeetingMemberDataInfoModel.h"

@interface AVDataInfoTableViewDelegateSource ()

@property (nonatomic, strong) MeetingViewController *meetingViewController;
@property (nonatomic, strong) NSMutableDictionary *dataItemDic;

@end


@implementation AVDataInfoTableViewDelegateSource

- (instancetype)initWithViewController:(NSViewController *)vc
{
    self = [super init];
    if (self)
    {
        self.meetingViewController = (MeetingViewController *) vc;
    }
    return self;
}

#pragma mark - NSTableViewDataSource
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
    if (tableView.tag == 100)
        return [LarkMeetingManager.localDataInfoArray count];
    else
        return [LarkMeetingManager.memberDataInfoArray count];
}

#pragma mark - NSTableViewDelegate
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    NSString *identifier = [NSString stringWithFormat:@"%zd%zd", tableColumn.identifier, row];
    NSTextField *cellTextField = self.dataItemDic[identifier];
    if (!cellTextField)
    {
        cellTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, tableColumn.width, 23)];
        cellTextField.bordered = NO;
        cellTextField.editable = NO;
        cellTextField.alignment = NSTextAlignmentCenter;
        cellTextField.backgroundColor = [NSColor clearColor];
        self.dataItemDic[identifier] = cellTextField;
    }
    
    switch (tableView.tag)
    {
        case 100:
        {
            MeetingLocalDataInfoModel *localModel = (MeetingLocalDataInfoModel *)LarkMeetingManager.localDataInfoArray[row];
            if ([tableColumn.identifier isEqualToString:@"columen00"])
                cellTextField.stringValue = localModel.channelName;
            else if ([tableColumn.identifier isEqualToString:@"columen01"])
                cellTextField.stringValue = localModel.codeRate;
            else if ([tableColumn.identifier isEqualToString:@"columen02"])
                cellTextField.stringValue = localModel.delay;
        }
            break;
        case 200:
        {
            MeetingMemberDataInfoModel *memberModel = (MeetingMemberDataInfoModel *)LarkMeetingManager.memberDataInfoArray[row];
            if ([tableColumn.identifier isEqualToString:@"columen10"])
            {
                cellTextField.stringValue = memberModel.userName;
            }
            else if ([tableColumn.identifier isEqualToString:@"columen11"])
            {
                cellTextField.stringValue = memberModel.tunnelName;
            }
            else if ([tableColumn.identifier isEqualToString:@"columen12"])
            {
                cellTextField.stringValue = memberModel.codec;
            }
            else if ([tableColumn.identifier isEqualToString:@"columen13"])
            {
                cellTextField.stringValue = memberModel.frame;
            }
            else if ([tableColumn.identifier isEqualToString:@"columen14"])
            {
                cellTextField.stringValue = memberModel.frameRate;
            }
            else if ([tableColumn.identifier isEqualToString:@"columen15"])
            {
                cellTextField.stringValue = memberModel.codeRate;
            }
            else if ([tableColumn.identifier isEqualToString:@"columen16"])
            {
                cellTextField.stringValue = memberModel.lossRate;
            }
        }
            break;
        default:
            break;
    }
    
    return cellTextField;
}

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
    return 18;
}

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
{
    return NO;
}

@end
